﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataVisualization
{
    public partial class DataVisualizer : Form
    {
        private InformationSet dataSet;

        

        public DataVisualizer()
        {
            InitializeComponent();
            dataSet = new InformationSet();

        }

        private void fileToolStripOpen_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openDatasetDialog = new OpenFileDialog();
                openDatasetDialog.Title = "Open New Dataset";
                openDatasetDialog.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
                openDatasetDialog.FilterIndex = 2;
                openDatasetDialog.RestoreDirectory = true;
                if (openDatasetDialog.ShowDialog() == DialogResult.OK)
                {
                    clearAll();
                    dataSet.FileName = openDatasetDialog.FileName;
                    dataSet.readFile();
                    foreach (string column in dataSet.Header)
                    {
                        dataGrid.Columns.Add(column, column);
                    }
                    foreach (VisualizationRow row in dataSet.Row)
                    {
                        dataGrid.Rows.Add(row.Items.ToArray());
                    }
                }
            }
            catch
            {

            }
        }
        private void clearAll()
        {
            try
            {
                dataGrid.Rows.Clear();
                dataGrid.Columns.Clear();
                dataSet.Clear();
            }
            catch
            {
            }
        }
        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            clearAll();
        }


        private void textToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TextWindow textWindow = new TextWindow(dataGrid);
            textWindow.Show();
        }

        private void groceryVisualizerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GroceryVisualizer groceryWindow = new GroceryVisualizer(dataGrid);
            groceryWindow.Show();
        }
    }
}
